/**
* 1_check_dimension
*/

#include <cuda_runtime.h>
#include <stdio.h>

__global__ void checkIndex() {
    printf("GPU: threadIdx: (%d, %d, %d), blockIdx(%d, %d, %d), blockDim(%d, %d, %d), gridDim(%d, %d, %d)\n",
           threadIdx.x, threadIdx.y, threadIdx.z,
           blockIdx.x, blockIdx.y, blockIdx.z,
           blockDim.x, blockDim, blockDim.z,
           gridDim.x, gridDim.y, gridDim.z);
}

int main() {
    int nElem = 6;
    dim3 block_thread(3); //定义每个块内部的线程数是3
    dim3 grid_block((nElem + block_thread.x - 1) / block_thread.x); //定义块数
    printf("CPU——grid中的block: block.x %d, block.y %d, block.z %d\n", grid_block.x, grid_block.y, grid_block.z);
    printf("CPU——block中的thread: thread.x %d, thread.y %d, thread.z %d\n", block_thread.x, block_thread.y, block_thread.z);
    checkIndex<<<grid_block, block_thread>>>();
    cudaDeviceReset();
    return 0;
}